package opl.ui;

import java.util.List;

import opl.entities.Team;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class TeamActivity extends Activity {

	private static List<Team> lstTeams;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.team);

		loadTeams();

		String teamName = getIntent().getStringExtra("TeamName");
		loadTeamData(teamName);
	}

	private void loadTeamData(String teamName) {
		Team selectedTeam = null;
		for (int i = 0; i < lstTeams.size(); i++) {
			Team t = lstTeams.get(i);
			if (t.getName().equalsIgnoreCase(teamName)) {
				selectedTeam = t;
				break;
			}
		}
		if (selectedTeam != null) {
			TextView tvName = (TextView) findViewById(R.id.tvName);
			TextView tvRating = (TextView) findViewById(R.id.tvRating);
			TextView tvCaptian = (TextView) findViewById(R.id.tvCaptian);
			TextView tvViceCaptian = (TextView) findViewById(R.id.tvViceCaptian);
			TextView tvOwner = (TextView) findViewById(R.id.tvOwner);
			TextView tvMembers = (TextView) findViewById(R.id.tvMembers);
			ListView lvMembers = (ListView) findViewById(R.id.lvMembers);

			tvName.setText(selectedTeam.getName());
			tvRating.setText("Rating : " + selectedTeam.getRating());
			tvCaptian.setText("Captian : " + selectedTeam.getCaptian());
			tvViceCaptian.setText("VC : " + selectedTeam.getViceCaptian());
			tvOwner.setText("Owner : " + selectedTeam.getOwner());
			tvMembers.setText(selectedTeam.getName() + " Members :");

			ArrayAdapter<String> adptr = new ArrayAdapter<String>(this,
					android.R.layout.simple_list_item_1,
					selectedTeam.getMembers());
			lvMembers.setAdapter(adptr);

		}
	}

	private void loadTeams() {
		lstTeams = Team.getTeams(this);
	}
}
